/*
 * @Author: 田鑫
 * @Date: 2023-03-05 14:57:17
 * @LastEditors: 田鑫
 * @LastEditTime: 2023-03-05 15:29:15
 * @Description: 用户相关状态
 */

type Role = 'ENTERPRISE' | 'PERSON';

interface UserState {
  role: Role;
  isLogin: boolean;
}

export const useUserStore = defineStore('user', {
  state: (): UserState => ({
    role: 'PERSON',
    isLogin: false,
  }),

  getters: {
    userRole(state) {
      return state.role;
    },
    userIsLogin(state) {
      return state.isLogin;
    },
  },

  actions: {
    setUserRole(role: Role) {
      this.role = role;
    },

    setUserLoginStatus(isLogin: boolean) {
      this.isLogin = isLogin;
    },

    async getUserInfo() {
      // todo 调用获取用户信息接口，当前用mock数据表示
      AMessage.success(`当前用户角色为：ENTERPRISE`)
      this.setUserRole('ENTERPRISE');
    },
  },
});
